package com.bj58.migrate.model;

import java.util.HashMap;
import java.util.Map;

import com.bj58.migrate.bll.IdcBll;
import com.bj58.sfft.utility.dao.annotation.Column;
import com.bj58.sfft.utility.dao.annotation.Id;
import com.bj58.sfft.utility.dao.annotation.NotDBColumn;
import com.bj58.sfft.utility.dao.annotation.Table;
import com.bj58.sfft.utility.dao.basedao.DAOBase;
import com.bj58.sfft.utility.dao.basedao.DAOHelper;
import com.bj58.sfft.utility.dao.basedao.IPreparedStatementHandler;

/**
 * Created by lvzheng on 2014/8/8.
 */
@Table( name = "t_avgsalary2015" )
public class AvgSalaryModel{
//	 static final String configPath ="D:/qiujizhaopinhui/com.bj58.move/conf/db0.properties";
	@NotDBColumn
	static final String configPath = "/opt/apps/app/avgsalary/conf/dbvote.properties";
	@NotDBColumn
	 static final IPreparedStatementHandler handler =new IPreparedStatementHandlerImpl();
	@NotDBColumn
	 static DAOHelper daoHelpers = null;
	 static{
		try{
			 daoHelpers = DAOBase.createIntrance(configPath);
		}catch(Exception e){
			e.printStackTrace();
		}
		}
	@Id
	private Long id;
	@Column( name = "localid" )
    private int localid;
	@Column( name = "cateid" )
    private int cateid;
	@Column( name = "catename" )
    private String catename;
	@Column( name = "localname" )
    private String localname;
	@Column( name = "infocount" )
    private volatile int infocount = 0;
	@Column( name = "avgsalary" )
    private volatile double avg = 0.0;      //保留2位小数
	@Column( name = "count_mianyi" )
    private volatile int count_mianyi = 0;
	@Column( name = "countless_1000" )
    private volatile int countless_1000 = 0;
	@Column( name = "count1000_2000" )
    private volatile int count1000_2000 = 0;
	@Column( name = "count2000_3000" )
    private volatile int count2000_3000 = 0;
	@Column( name = "count3000_5000" )
    private volatile int count3000_5000 = 0;
	@Column( name = "count5000_8000" )
    private volatile int count5000_8000 = 0;
	@Column( name = "count8000_12000" )
    private volatile int count8000_12000 = 0;
	@Column( name = "count12000_20000" )
    private volatile int count12000_20000 = 0;
	@Column( name = "count20000_25000" )
    private volatile int count20000_25000 = 0;
	@Column( name = "countthan_25000" )
    private volatile int countthan_25000 = 0;
	@Column( name = "startdate" )
    private int startdate;
	@Column( name = "enddate" )
    private int enddate;

    public void info_IncrementAndGet(){
        this.infocount++;
    }

    public void setInterval( String paramValue ){

        if( paramValue != null && paramValue.length() > 0 ){

            Integer salary = jobSarayMap.get( paramValue.replace( "_", "-" ) );

            if( salary != null ){

                this.info_IncrementAndGet();
                switch( salary ){
                    case 0:
                        this.count_mianyi_IncrementAndGet();
                        break;
                    case 999:
                        this.countless_1000_IncrementAndGet();
                        break;
                    case 1500:
                        this.count1000_2000_IncrementAndGet();
                        break;
                    case 2500:
                        this.count2000_3000_IncrementAndGet();
                        break;
                    case 4000:
                        this.count3000_5000_IncrementAndGet();
                        break;
                    case 6500:
                        this.count5000_8000_IncrementAndGet();
                        break;
                    case 10000:
                        this.count8000_12000_IncrementAndGet();
                        break;
                    case 16000:
                        this.count12000_20000_IncrementAndGet();
                        break;
                    case 22500:
                        this.count20000_25000_IncrementAndGet();
                        break;
                    case 99999:
                        this.countthan_25000_IncrementAndGet();
                        break;
                    default:
                }
            }
        }
    }

    public void count_mianyi_IncrementAndGet(){
        this.count_mianyi++;
    }

    public void countless_1000_IncrementAndGet(){
        this.countless_1000++;
    }

    public void countthan_25000_IncrementAndGet(){
        this.countthan_25000++;
    }

    public void count1000_2000_IncrementAndGet(){
        this.count1000_2000++;
    }

    public void count2000_3000_IncrementAndGet(){
        this.count2000_3000++;
    }

    public void count3000_5000_IncrementAndGet(){
        this.count3000_5000++;
    }

    public void count5000_8000_IncrementAndGet(){
        this.count5000_8000++;
    }

    public void count8000_12000_IncrementAndGet(){
        this.count8000_12000++;
    }

    public void count12000_20000_IncrementAndGet(){
        this.count12000_20000++;
    }

    public void count20000_25000_IncrementAndGet(){
        this.count20000_25000++;
    }

    public void caculateAvg(){
    	int count = this.count1000_2000+this.count2000_3000+this.count3000_5000+this.count5000_8000+this.count8000_12000+this.count12000_20000+this.count20000_25000;
    	double avg = 0.00;
		if (count > 0) {
        avg = ( this.count1000_2000 * 1500 + this.count2000_3000 * 2500 + this.count3000_5000 * 4000 + this.count5000_8000 * 6500 +
                       this.count8000_12000 * 10000 + this.count12000_20000 * 16000 + this.count20000_25000 * 22500 ) / count;
    	}
        this.avg = avg;
    }

    /**
     * 写入日志或者DB
     * @throws Exception 
     */
    public void write() throws Exception{

		IdcBll idcBll = new IdcBll();
		Long id = idcBll.getId();
		StringBuffer sql = new StringBuffer( "insert into t_avgsalary2015(id,localid,cateid,localname,catename,avgsalary,count_mianyi,countless_1000,count1000_2000,count2000_3000,count3000_5000,count5000_8000,count8000_12000,count12000_20000,count20000_25000,countthan_25000,infocount,startdate,enddate,level1) values(" ).append( id + "," )
			.append(this.localid+",")
			.append(this.cateid+",")
			.append("'"+this.localname+"',")
			.append("'"+this.catename+"',")
			.append(this.avg+",")
			.append(this.count_mianyi+",")
			.append(this.countless_1000+",")
			.append(this.count1000_2000+",")
			.append(this.count2000_3000+",")
			.append(this.count3000_5000+",")
			.append(this.count5000_8000+",")
			.append(this.count8000_12000+",")
			.append(this.count12000_20000+",")
			.append(this.count20000_25000+",")
			.append(this.countthan_25000+",")
			.append(this.infocount+",")
			.append(this.startdate+",")
.append( this.enddate + "," ).append( "0)" );
		String condition = sql.toString();
		System.out.println( condition );
		daoHelpers.execInsert( condition, handler );
    }

    public void show(){

        //System.out.println( "this.infocount:" + this.infocount );
    	System.out.println("##################localid="+this.localid+"cateid="+this.cateid+"catename="+this.catename+""+this.localname+"infocount ="+this.infocount+"avg="
        +this.avg+"count_mianyi="+this.count_mianyi+"countless_1000="+this.countless_1000+"count1000_2000="+this.count1000_2000+"count2000_3000="+this.count2000_3000+
        "count3000_5000="+this.count3000_5000+"count5000_8000="+this.count5000_8000+"count8000_12000="+this.count8000_12000+"count12000_20000:"+this.count12000_20000+
        "count20000_25000="+this.count20000_25000+"countthan_25000="+this.countthan_25000+"startdate="+this.startdate+"enddate:"+this.enddate);
    }

	@NotDBColumn
    private static final Map< String, Integer > jobSarayMap = new HashMap< String, Integer >();

    static{

        jobSarayMap.put( "面议-面议", 0 );
        jobSarayMap.put( "1-999", 999 );
        jobSarayMap.put( "1000-2000", 1500 );
        jobSarayMap.put( "2000-3000", 2500 );
        jobSarayMap.put( "3000-5000", 4000 );
        jobSarayMap.put( "5000-8000", 6500 );
        jobSarayMap.put( "8000-12000", 10000 );
        jobSarayMap.put( "12000-20000", 16000 );
        jobSarayMap.put( "20000-25000", 22500 );
        jobSarayMap.put( "25000-25000", 99999 );

        jobSarayMap.put( "面议", 0 );
        jobSarayMap.put( "1000-1999", 999 );
        jobSarayMap.put( "1000-1999", 1500 );
        jobSarayMap.put( "2000-2999", 2500 );
        jobSarayMap.put( "3000-4999", 4000 );
        jobSarayMap.put( "5000-7999", 6500 );
        jobSarayMap.put( "8000-12000", 10000 );
        jobSarayMap.put( "12000-19999", 16000 );
        jobSarayMap.put( "20000-24999", 22500 );
        jobSarayMap.put( "25000-99999", 99999 );
    }

    //-------------------getset-------------------//

    public int getCateid(){
        return cateid;
    }

    public void setCateid( int cateid ){
        this.cateid = cateid;
    }

    public int getLocalid(){
        return localid;
    }

    public void setLocalid( int localid ){
        this.localid = localid;
    }

    public String getCatename(){
        return catename;
    }

    public void setCatename( String catename ){
        this.catename = catename;
    }

    public String getLocalname(){
        return localname;
    }

    public void setLocalname( String localname ){
        this.localname = localname;
    }

	public Long getId(){
        return id;
    }

	public void setId( Long id ){
        this.id = id;
    }

    public int getEnddate(){
        return enddate;
    }

    public void setEnddate( int enddate ){
        this.enddate = enddate;
    }

    public int getStartdate(){
        return startdate;
    }

    public void setStartdate( int startdate ){
        this.startdate = startdate;
    }

    public int getCount_mianyi(){
        return count_mianyi;
    }

    public int getCountless_1000(){
        return countless_1000;
    }

    public int getCountthan_25000(){
        return countthan_25000;
    }

    public double getAvg(){
        return avg;
    }

    public int getCount1000_2000(){
        return count1000_2000;
    }

    public int getCount2000_3000(){
        return count2000_3000;
    }

    public int getCount3000_5000(){
        return count3000_5000;
    }

    public int getCount5000_8000(){
        return count5000_8000;
    }

    public int getCount8000_12000(){
        return count8000_12000;
    }

    public int getCount12000_20000(){
        return count12000_20000;
    }

    public int getCount20000_25000(){
        return count20000_25000;
    }

	public void setInfocount(int infocount) {
		this.infocount = infocount;
	}

	public int getInfocount(){
		return infocount;
	}

	public void setCount_mianyi(int count_mianyi) {
		this.count_mianyi = count_mianyi;
	}

	public void setCountless_1000(int countless_1000) {
		this.countless_1000 = countless_1000;
	}

	public void setCount1000_2000(int count1000_2000) {
		this.count1000_2000 = count1000_2000;
	}

	public void setCount2000_3000(int count2000_3000) {
		this.count2000_3000 = count2000_3000;
	}

	public void setCount3000_5000(int count3000_5000) {
		this.count3000_5000 = count3000_5000;
	}

	public void setCount5000_8000(int count5000_8000) {
		this.count5000_8000 = count5000_8000;
	}

	public void setCount8000_12000(int count8000_12000) {
		this.count8000_12000 = count8000_12000;
	}

	public void setCount12000_20000(int count12000_20000) {
		this.count12000_20000 = count12000_20000;
	}

	public void setCount20000_25000(int count20000_25000) {
		this.count20000_25000 = count20000_25000;
	}

	public void setCountthan_25000(int countthan_25000) {
		this.countthan_25000 = countthan_25000;
	}

	public void setAvg( double avg ){
		this.avg = avg;
	}
    
}
